﻿using UnityEngine;
using UnityEngine.UIElements;
using winS.UnityEditor.UIElement;
using Button = winS.UnityEditor.UIElement.Button;

namespace winS.UnityEditor.ProcessEditor
{
    public class InfoBar : VisualElement
    {
        public readonly Filter filter;
        public readonly History history;
        public readonly Button fileButton;
        public readonly Button settingButton;
        public readonly Button refreshButton;

        public InfoBar(ProcessEditorData processEditorData)
        {
            style.flexShrink = 0f;
            style.borderTopWidth = 1f;
            style.borderBottomWidth = 1f;
            style.flexDirection = FlexDirection.Row;
            style.SetBorderTopColor(35, 35, 35);
            style.SetBorderBottomColor(0, 0, 0);

            Add(fileButton = EditorElementUtility.elementFactory.CreateButton(Resources.Load<Texture>("winS.UnityEditor.ProcessEditor/Icons/历史记录"), 16f));
            Add(history = new History(processEditorData.historyData));
            Add(refreshButton = EditorElementUtility.elementFactory.CreateButton(Resources.Load<Texture>("winS.UnityEditor.ProcessEditor/Icons/刷新"), 16f));
            Add(filter = new Filter());
            Add(settingButton = EditorElementUtility.elementFactory.CreateButton(Resources.Load<Texture>("winS.UnityEditor.ProcessEditor/Icons/设置"), 16f));

            fileButton.SetEnabled(false);
            fileButton.style.SetBorderWidth(0);
            settingButton.style.SetBorderWidth(0f);
            refreshButton.style.SetBorderWdith(0f);
            fileButton.normalColor = refreshButton.normalColor = settingButton.normalColor = Color.clear;
            refreshButton.style.marginRight = refreshButton.style.marginLeft = settingButton.style.marginRight = settingButton.style.marginLeft = 2f;
        }

        public void EnterEditingState(EditorProcessInfo editorProcessInfo)
        {
            history.SetCurrentFile(editorProcessInfo);
            fileButton.SetEnabled(true);
        }
        public void ExitEditingState()
        {
            history.ClearCurrentFile();
            fileButton.SetEnabled(false);
        }
    }
}